$(document).ready(function() {
	courses($(".chosen").attr("id"));
});

$(document).delegate('.filter', 'click', function() {
	if (!($(this).hasClass("chosen"))) {
		$(".chosen").removeClass("chosen");
		$(this).addClass("chosen");
		courses($(this).attr("id"));
	}
});

function courses(type) {
	$(".wait").show();
	$("#courses-table").hide();
	data = $("#filters").serialize();
	$.ajax({
		type:"POST",
		url: $("#project-base").val()+'Courses',
		async: true,
		data: data+"&type="+type,
		success:function(msg) {
			$("#courses-table").html(msg);
			$("#courses-error").html("");
			setTimeout('$("#courses-table").show();$(".wait").hide();',500);
		},
		error:function(msg) {
			$("#courses-error").html(msg.responseText);
		}
	});
}